package com.bufbomb.datastore;

import com.google.appengine.api.datastore.Text;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.Order;


@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class FlashItem {
	
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

    @Persistent
    private String name;

    @Persistent
    private Text description;
    
    @Persistent
    private Date uploadDate;
    
    @Persistent
    private int count;
    
    @Persistent
    @Order(extensions = @Extension(vendorName="datanucleus", key="list-ordering", value="order asc"))

    private List<DataItem> dataItems;
    public FlashItem(String name, Text description) {
    	this.name = name;
    	this.description = description;
    	this.count = 0;
    	this.uploadDate = new Date(); 
    }

    public long getId() {
    	return this.id;
    }
    
    public String getName() {
        return this.name;
    }

    public String getDescription() {
        return this.description.getValue();
    }
    
    public int getCount()
    {
    	return this.count;
    }
    public String getDate()
    {
    	Calendar c = Calendar.getInstance();
    	c.setTime(this.uploadDate);
    	return c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH)+ 1) + "月" + c.get(Calendar.DATE) + "日"; 
    }
    
    public void setDataItems(List<DataItem> items){
    	this.dataItems = items;
    }
    
    public List<DataItem> getDataItems(){
    	return this.dataItems;
    }
}
